using System.Data;

namespace System.Resources.SqlResource
{
    /// <summary>
    /// Enumerates resources, reading sequential resource name and value pairs.
    /// </summary>
    public sealed class SqlResourceReader : IResourceReader
    {
        private readonly Globalization.CultureInfo _ci = null;

        /// <summary>
        /// Initializes a new instance of the ResourceReader class for the specified Culture Info.
        /// </summary>
        /// <param name="ci">The Culture Info to be read. </param>
        public SqlResourceReader(Globalization.CultureInfo ci)
        {
            _ci = ci;
        }

        public DataTable GetResourcesData
        {
            get 
            {
                CSUtil u = new CSUtil();
                ISqlResourceGetData s = u.CreateInstance();
                return s.GetResources(_ci);                
            }
        }

        public Collections.IDictionaryEnumerator GetEnumerator()
        {
            CSUtil u = new CSUtil();
            ISqlResourceGetData s = u.CreateInstance();
            System.Diagnostics.Trace.WriteLine("SqlResourceReader::System.Collections.IDictionaryEnumerator -> Get Data from DB...");
            DataTable dt = s.GetResources(_ci);
            System.Diagnostics.Trace.WriteLine("SqlResourceReader::System.Collections.IDictionaryEnumerator -> ...End Data DB.");
            return new CSResources(dt);
        }

        Collections.IEnumerator Collections.IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }

        public void Close()
        {
            return;
        }

        public void Dispose()
        {
            Close();
        }
    }
}
